<template>
	<view class="contain">
		<view class="info" @click="checkheader">
			<view class="left">
				头像
			</view>
			<view class="right flexright" >
				<image :src="userclaerinfo.faceImages" mode=""></image>
					<view class="deg1">			
				    </view>
			</view>
			
		</view>
		<view class="info" @click="editnickname">
			<view class="left">
				昵称
			</view>
			<view class="right">
				{{userclaerinfo.nickname}} >
			</view>
		</view>
		<view class="info" @click="editbirth">
			<view class="left">
				生日
			</view>
			<view class="right">
				{{userclaerinfo.birthday}}>
			</view>
		</view>
		<view class="info" @click="editsex">
			<view class="left">
				性别 
			</view>
			<view class="right">
				{{userclaerinfo.sex==null?'未设置':userclaerinfo.sex}}>
			</view>
		</view>
		<view class="footer">
			<view class="clear" @click="clearstroge">
				清理缓存
			</view>
			<view class="offlogin" @click="offloginuser">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import common from '../../common/common.js'
	export default {
		data() {
			return {
				userclaerinfo:{}
			}
		},
		onShow() {
			var info = uni.getStorageSync("globaluser")
			console.log(info)
			this.userclaerinfo = info
		},
		methods: {
			clearstroge(){
				uni.removeStorage({
					key:"globaluser"
				})
				uni.showToast({
					title:"清理缓存成功",
					mask:false,
					duration:1500,
				})
				
			},
			editbirth(){
				uni.navigateTo({
					url:'../editbirth/editbirth?birthday='+this.userclaerinfo.birthday
				})
			},
			editsex(){
				uni.navigateTo({
					url:'../sex/sex'
				})
			},
			checkheader(){
				var me = this
				uni.showActionSheet({
					itemList:['查看我的头像','从相册选择上传'],
					success(res) {
						var index = res.tapIndex
						if(index == 0) {
							var imgarr = []
							imgarr.push(me.userclaerinfo.faceImages)
							uni.previewImage({
								urls:imgarr,
								current:imgarr[0]
							})
						}else{
							uni.navigateTo({
								url:'../meface/meface?imgurl='+me.userclaerinfo.faceImages
							})
						}
					}
				})
			},
			editnickname(){
				uni.navigateTo({
					url:'../editname/editname?username='+this.userclaerinfo.nickname
				})
			},
			offloginuser(){
				var globaluser = this.getGlobalUser("globaruser")
				console.log(globaluser)
				uni.request({
					url:common.serverUrl+'/user/logout?userId='+globaluser.id,
					method:"POST",
					success(res) {
						uni.showToast({
							title:"退出成功",
							mask:false,
							duration:4000,
							image:'../../static/logout.png',
							
							success:(res)=> {
								uni.removeStorage({
									key:"globaluser"
								})
								uni.switchTab({
									url:"../profile/profile"
								})
							}
						})
					}
					
				})
			}
		}
	}
</script>

<style>
@import url("./setting.css");
</style>
